<template>
    <div class="setorder-center">
        <van-nav-bar left-text="返回" left-arrow @click-left="onClickLeft" />
        <van-address-list v-model="chosenAddressId" :list="list" default-tag-text="默认" @select="onselect" @add="onAdd"
            @edit="onEdit" />
    </div>
</template>
<script>
import { list } from "../../api/index.js"
import { Toast, AddressList } from 'vant';
export default {
    name: 'setorder',
    data() {
        return {
            chosenAddressId: "0",
            list: [],
            data: []
        }
    },
    methods: {
        onselect(item, index) {
            this.data = []
            this.data.push(item)
            var ac = localStorage.getItem("active")
            this.$router.push({
                path: ac,
                query: {

                    address: item.address,
                    id: item.id,
                    name: item.name,
                    tel: item.tel

                }
            })
            // this.$router.go(-1)
        },
        onAdd() {
            
            this.$router.push({ path: '/orderadd' })
        },
        onEdit(item, index) {
            Toast('编辑地址:' + index);
        },
        onClickLeft() {
            // var add = localStorage.getItem("active")
            // console.log(add)
            // this.$router.push({ path: add })
            this.$router.go(-1)

        },

    },
    mounted() {
        list().then(res => {
            for (let index = 0; index < res.data.data.list.length; index++) {
                res.data.data.list[index].address = res.data.data.list[index].province + "" + res.data.data.list[index].county + "" + res.data.data.list[index].city + "" + res.data.data.list[index].addressDetail
            }
            this.list = res.data.data.list
        })

    }
}
</script>
<style lang="scss">
.setorder-center {
    height: 100vh;
    background-color: #F2F2F2;
}
</style>